package StudyCode.summary.zipfile;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CreateZipFileUsingZipOutputStream {
	public static void main(String args[]) {
		try {
			String zipFile = "E:/Copy/test.zip";
			String sourceFile = "E:/Copy/csv.csv";

			byte[] buffer = new byte[1024];
			FileOutputStream fout = new FileOutputStream(zipFile);

			ZipOutputStream zout = new ZipOutputStream(fout);

			FileInputStream fin = new FileInputStream(sourceFile);

			zout.putNextEntry(new ZipEntry(sourceFile));

			int length;

			while ((length = fin.read(buffer)) > 0) {
				zout.write(buffer, 0, length);
			}

			zout.closeEntry();
			fin.close();

			zout.close();

			System.out.println("Zip文件创建成功!");

		} catch (IOException ioe) {
			ioe.printStackTrace();
		}

	}
}
